<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改弹框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/static/admin/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/admin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/webupload/xb-webuploader.css">
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
</head>

<body>
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>修改弹框</legend>
    </fieldset>

    <form class="layui-form" style="width:1000px;" action="/ad/edit" id="addForm">
        <input name="id" type="hidden" value="{$row.id}">
        <div class="layui-tab-item layui-show">
            <div class="layui-form-item">
                <label class="layui-form-label">弹框标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" autocomplete="off" value="{$row.title}" class="layui-input" maxlength="20">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">关联活动</label>
                <div class="layui-input-block">
                    <select name="activity_id" lay-verify="required" lay-search>
                        <option value="0">所有活动</option>
                        {foreach name="activity" item="val" key="key"}
                        <option value="{$val.id}" {if condition="$val['id'] eq $row['activity_id']"}selected{/if}>{$val.title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">显示时间</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline min-width">
                        <input name="start_time"  lay-verify="required" value="{$row.start_time}" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})" type="text">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline min-width">
                        <input name="end_time"  lay-verify="required" value="{$row.end_time}" autocomplete="off" class="layui-input" onclick="layui.laydate({elem: this})" type="text">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">弹出图片</label>
                <div class="layui-input-block">
                    <input type="hidden" name="ad" id="logo" autocomplete="off" class="layui-input" value="{$row.ad}">
                    <div id="logo_upload" class="wu-example logo">
                        <div class="uploader-list logo">
                            <img src="{$row.ad}" id="logoImg">
                        </div>
                        <div class="webuploader-container logo" >
                            <div class="webuploader-pick">选择图片</div>
                        </div>
                        <div class="fileMsg logo"></div>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">活动说明</label>
                <div class="layui-input-block long">
                    <textarea id="editor" name="content" style="" class="layui-textarea">{$row.content}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo">立即提交</button>
                    <a class="layui-btn layui-btn-primary" href="/ad/index">返回上一级</a>
                </div>
            </div>
        </div>
    </form>
</div>
<style>
    .layui-input-block{
        width: 500px;
    }
    .layui-input-block.long{
        width: 70%;
    }

    .wu-example.logo{
        height:100px;
    }
    .webuploader-container.logo{
        width:76px;
        height:43px;
        float: left;
    }
    .uploader-list.logo{
        width:100px;
        height:100px;
        float: left;
        margin-left:5px;
    }
    .uploader-list img{
        height:100px;
    }
    .fileMsg.logo{
        float: left;
    }

</style>
<script type="text/javascript" src="/static/admin/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/webupload/webuploader.min.js"></script>
<script type="text/javascript" src="/static/webupload/webuploader-one.js"></script>
<script type="text/javascript" src="/static/webupload/webuploader-set.js"></script>
<script>

    layui.use(['form', 'laydate', 'element'], function () {
        var form = layui.form(),
            layer = layui.layer,
            element = layui.element(),
            laydate = layui.laydate;

        uploadOne('#logo_upload', '#logo', WebUploader, '#logoImg');
        //监听提交
        form.on('submit(demo)', function(data) {
            var url = $(data.form).attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data:  data.field,
                async: true,
                beforeSend: function () {
                    jz = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                },
                error: function (request) {
                    layer.close(jz);
                    layer.alert('网络错误',{icon:2}, function(index){
                        layer.close(index);
                    });
                },
                success: function (data) {
                    //关闭加载层
                    layer.close(jz);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1500
                        }, function(){
                            window.location.href = data.data.url;
                        });
                    } else if(data.code == -1){
                        window.location.href = '/login/login';
                    }else {
                        layer.alert(data.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
